package com.dnjn.happiness.system.api.factory;

import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.common.core.model.SysPostVO;
import com.dnjn.happiness.system.api.RemotePostService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemotePostFallbackFactory implements FallbackFactory<RemotePostService> {

    private static final Logger log = LoggerFactory.getLogger(RemotePostFallbackFactory.class);

    @Override
    public RemotePostService create(Throwable throwable) {
        log.error("调用岗位微服务失败：{}" + throwable.getMessage());
        return new RemotePostService() {
            @Override
            public R<SysPostVO> getInfoById(Long postId, String source) {
                return R.fail("查询岗位信息失败：" + throwable.getMessage());
            }

            @Override
            public R<List<SysPostVO>> queryPostListByDeptId(Long deptId, String source) {
                return R.fail("查询岗位列表信息失败：" + throwable.getMessage());
            }

            @Override
            public R<List<SysPostVO>> selectPostsByUserId(Long userId, String source) {
                return R.fail("查询岗位列表信息失败：" + throwable.getMessage());
            }
        };
    }
}
